/*
	Copyright 2007-2010 Petr Ohlidal

	This file is a part of GrobMaker

	GrobMaker is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	GrobMaker is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with GrobMaker.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "FileInfo.hpp"

namespace GrobMaker{

int FileInfo::parseFileNameIndex(const std::string& name){
	int digitIndex(0);
	int l = static_cast<int>(name.length());
	char* digits = new char[l+1];
	for(int i(0); i<l; i++){
		if(isdigit(name.at(i))){
			digits[digitIndex] = name.at(i);
			digitIndex++;
		}
	}
	digits[digitIndex] = '\0';
	if(digitIndex==0){//No digits in file name
		delete digits;
		return FileInfo::noIndex;
	}
	else{
		int fileNameIndex = static_cast<int>(strtol(digits, NULL, 10));
		delete digits;
		return fileNameIndex;
	}
}

} // namespace GrobMaker
